﻿<%@ WebHandler Language="C#" Class="ASH013" %>

using System;
using System.Web;
using System.Text;
using System.Data;
using Com.LongER.Business;
using Com.LongER.Business.COMMON;
using System.Collections.Generic;

public class ASH013 : IHttpHandler {
    
    /// <summary>
    /// 取车辆装载状态
    /// </summary>
    /// <param name="context"></param>
    public void ProcessRequest (HttpContext context) {
        String strKEY1 = context.Request.QueryString["KEY1"];
        strKEY1 = strKEY1.ToUpper();

        CCOMMON instance = new CCOMMON();

        COMMONDS.M_TONGYONGDataTable dt = instance.Get共通();

        var query = from data in dt
                    where data.KEY1.StartsWith(strKEY1)
                        && data.CODE_CD == "ZZZT"
                    orderby data.KEY1
                    select new
                    {
                        KEY1 = data.KEY1,
                        CODE1_HANZI = data.CODE1_HANZI
                    };
        
        Boolean isExistQuery = false;

        StringBuilder jsonBuilder = new StringBuilder();
        jsonBuilder.Append("[");

        foreach (var r in query)
        {
            isExistQuery = true;
            jsonBuilder.Append("{");
            jsonBuilder.Append("\"KEY1\":").Append("\"").Append(r.KEY1).Append("\"").Append(",");
            jsonBuilder.Append("\"CODE1_HANZI\":").Append("\"").Append(r.CODE1_HANZI).Append("\"");
            jsonBuilder.Append("},");
        }

        jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
        jsonBuilder.Append("]");

        //context.Response.Clear();
        context.Response.Charset = "utf-8";
        context.Response.Buffer = true;
        context.Response.ContentEncoding = System.Text.Encoding.UTF8;
        context.Response.ContentType = "text/plain";
        context.Response.Write(isExistQuery == true ? jsonBuilder.ToString() : "");
        //context.Response.Flush();
        //context.Response.Close();
        //context.Response.End();
    }
 
    /// <summary>
    /// 
    /// </summary>
    public bool IsReusable {
        get {
            return false;
        }
    }

}